<?php

/* * ***********************************************************************************
 *
 * 	FileName: header_php.php
 * 	Desc    : This will do a user activation from mail link
 * 	Author  : Jensen
 * 	Date    : 2010-10-22
 *
 * *********************************************************************************** */
require_once( ROOT_DIR . "config.inc.php" );
//require_once( ROOT_DIR . "uc_client/client.php" );

$uid = GET("uid");
$username = mb_convert_encoding(GET("username"), "UTF-8", "gb2312");
$code = GET("c");
$pwd = base64_decode( GET('stamp') );

$iid = GET("iid");

$pageVars = array();
$isvalid = IsActivationCodeValid($uid, $username, $code);
if ($isvalid) {
    $userdao = GetUserDAO();
    $userinfo = $userdao->GetUserByID($uid);
    $username = $userinfo['nick'];
    $issucceed = $userdao->UserActivation($uid);
    if ($issucceed) {

        //add by bo @10.26
        if ($iid > '0') {

            if (($inviter = $userdao->GetUserByID($iid)) != false) {

                $para['uid'] = $uid;
                $eventDispatcher = GetEventDispatcher();
                $eventDispatcher->Notify($inviter['id'], INVITE_FRIEND_SUCCESS, $para);

                $mail = GetMailer();
                $mail->SendInviteSuccessMail($inviter['email'], $inviter['nick'], $username, $uid);
            }
        }

        //make sure user has logout
        logoutUser();
        //means activation succeed
        $pageVars['status'] = 1;
        LoginAsUser($uid, $username);

//        list($id, $username, $password, $email) = uc_user_login( $username, $pwd );
//		if($id > 0) {
//			$ucsynlogin = uc_user_synlogin($id);
//			echo $ucsynlogin;
//		}
//		else{
//			//echo "登陆其它系统失败";
//		}

        TransferTo('activation_succeed');
    } else {
        //means already activated or account disabled or something
        $pageVars['status'] = 2;
        TransferTo('activation_failed');
    }
} else {
    //means activation failed
    $pageVars['status'] = 0;
    TransferTo('activation_failed');
}
?>
